﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using HelperLibrary;
using BackupLibrary;
using MasterLibrary.Windows.Forms.Aero;

namespace Prometheus
{
    public partial class wzSettingsTime : WizardPage
    {
        public wzSettingsTime()
        {
            InitializeComponent();
            this.ReloadConfiguration();
        }

        public void ReloadConfiguration()
        {
            this.chkInterval.Checked = Globals.appConfig.UseInterval;
            this.chkRequest.Checked = Globals.appConfig.UseRequest;
            this.chkWait.Checked = Globals.appConfig.UseWait;

            if (Globals.appConfig.ValueInterval != 0)
                this.numInterval.Value = Globals.appConfig.ValueInterval;
            if (Globals.appConfig.ValueWait != 0)
                this.numWait.Value = Globals.appConfig.ValueWait;

            this.cmbInterval.Text = GetTimetypeString(Globals.appConfig.TypeInterval);
            this.cmbWait.Text = GetTimetypeString(Globals.appConfig.TypeWait);

            this.pickDate.Value = Globals.appConfig.StartTime;
            this.pickTime.Value = Globals.appConfig.StartTime;

            this.lblBackup.Text = Globals.appConfig.LastBackup;
        }

        private string GetTimetypeString(Timetype type)
        {
            switch (type)
            {
                case Timetype.Days:
                    return "Tage";
                case Timetype.Hours:
                default:
                    return "Stunden";
                case Timetype.Minutes:
                    return "Minuten";
                case Timetype.Months:
                    return "Monate";
                case Timetype.Weeks:
                    return "Wochen";
            }
        }
        private Timetype GetTimetype(string type)
        {
            switch (type)
            {
                case "Tage":
                    return Timetype.Days;
                case "Stunden":
                default:
                    return Timetype.Hours;
                case "Minuten":
                    return Timetype.Minutes;
                case "Monate":
                    return Timetype.Months;
                case "Wochen":
                    return Timetype.Weeks;
            }
        }

        private void chkInterval_CheckedChanged(object sender, EventArgs e)
        {
            Globals.appConfig.UseInterval = this.chkInterval.Checked;
            Globals.SaveConfiguration(Globals.appConfig);
        }

        private void chkWait_CheckedChanged(object sender, EventArgs e)
        {
            Globals.appConfig.UseWait = this.chkWait.Checked;
            Globals.SaveConfiguration(Globals.appConfig);
        }

        private void chkRequest_CheckedChanged(object sender, EventArgs e)
        {
            Globals.appConfig.UseRequest = this.chkRequest.Checked;
            Globals.SaveConfiguration(Globals.appConfig);
        }

        private void numInterval_ValueChanged(object sender, EventArgs e)
        {
            Globals.appConfig.ValueInterval = (int)this.numInterval.Value;
            Globals.SaveConfiguration(Globals.appConfig);
        }

        private void numWait_ValueChanged(object sender, EventArgs e)
        {
            Globals.appConfig.ValueWait = (int)this.numWait.Value;
            Globals.SaveConfiguration(Globals.appConfig);
        }

        private void cmbInterval_SelectedIndexChanged(object sender, EventArgs e)
        {
            Globals.appConfig.TypeInterval = GetTimetype(this.cmbInterval.Text);
            Globals.SaveConfiguration(Globals.appConfig);
        }

        private void cmbWait_SelectedIndexChanged(object sender, EventArgs e)
        {
            Globals.appConfig.TypeWait = GetTimetype(this.cmbWait.Text);
            Globals.SaveConfiguration(Globals.appConfig);
        }

        private void pickDate_ValueChanged(object sender, EventArgs e)
        {
            this.pickTime.Value = this.pickDate.Value;
            Globals.appConfig.StartTime = this.pickDate.Value;
            Globals.SaveConfiguration(Globals.appConfig);
        }

        private void pickTime_ValueChanged(object sender, EventArgs e)
        {
            this.pickDate.Value = this.pickTime.Value;
            Globals.appConfig.StartTime = this.pickTime.Value;
        }
    }
}
